<template>
  <div class="home-box">
    <!-- 头部导航 -->
    <!-- 自定义指令 -->
    <van-nav-bar class="page-nav" fixed>
      <van-button to="/search" type="info" class="search-btn" slot="title" size="small" round icon="search">搜索
      </van-button>
    </van-nav-bar>
    <!-- 标签页 -->
    <van-tabs class="channel-tab" v-model="active" animated swipeable>
      <van-tab :title="item.name" v-for="item in userDataList" :key="item.id">
        <ArticleList :pannelId="item.id" />
      </van-tab>
      <!-- 面包王 -->
      <div slot="nav-right" class="nav-right" @click="isshowEdit=true">
        <i class="toutiao toutiao-gengduo"></i>
      </div>
      <div slot="nav-right" class="placeholder"></div>
    </van-tabs>
    <!-- 弹出层 -->
    <van-popup close-icon-position="top-left" v-model="isshowEdit" closeable position="bottom"
      :style="{ height: '90%' }">
      <PorupModel @sendData='getEdit' :userDataList=" userDataList" :active="active" />
    </van-popup>
  </div>
</template>

<script>
import { getUserPannel } from '@/api/users.js'

import ArticleList from './compontns/ArticleList.vue'
import PorupModel from './compontns/porup_model.vue'
// import { dataFormate } from '@/filters/index.js'
import { getItem } from '../../utils/storege'
export default {
  // 局部自定义指令
  // directives: {
  //   focus: {
  //     inserted: function (el) {
  //       el.focus()
  //     }
  //   }
  // },
  components: {
    ArticleList,
    PorupModel
  },
  data () {
    return {
      active: 0,
      userDataList: [],
      // 弹出层、
      isshowEdit: false
      // name: '赵西文'
    }
  },
  created () {
    this.loadUserPannel()
  },
  // 用户频道
  methods: {
    async loadUserPannel () {
      // 判断用户是否登录
      const data = getItem('hmtt-channel')
      if (!this.$store.state.user && getItem('hmtt-channel')) {
        this.userDataList = data
      } else {
        try {
          const { data: res } = await getUserPannel()
          console.log(res)
          this.userDataList = res.data.channels
        } catch (err) {
          this.$toast('获取失败')
        }
      }
    },
    // 获取子组件的时间函数
    getEdit (e) {
      this.isshowEdit = e.close
      this.active = e.index
    }

  }
}
</script>

<style lang="less" scoped>
.home-box {
  // 搜索
  padding-top: 174px;
  padding-bottom: 100px;
  .search-btn {
    width: 555px;
    height: 64px;
    background-color: #5babfb;
    border-radius: 32px;
    border: none;
  }
  /deep/.van-icon-search {
    color: #fff;
  }
  /deep/.van-nav-bar__title {
    max-width: unset;
  }
  // 频道
  /deep/.channel-tab {
    .van-tabs__wrap {
      position: fixed;
      top: 92px;
      width: 100%;
      z-index: 2;
    }
    .van-tab {
      height: 82px;
      min-width: 200px;
      border-right: 1px solid #edeff3;
      .van-tab__text {
        font-size: 28px;
        color: #777;
      }
    }

    .van-tab--active {
      .van-tab__text {
        font-size: 30px;
        color: #333;
      }
    }
    // 条
    .van-tabs__line {
      width: 31px;
      height: 6px;
      background-color: #3296fa;
      border-radius: 3px;
      bottom: 8px;
    }
    .van-tabs__nav {
      padding: 0;
    }
    // 右侧的汉堡
    .nav-right {
      width: 66px;
      height: 82px;
      background-color: #fff;
      opacity: 0.902;
      position: fixed;
      right: 0;
      display: flex;
      justify-content: center;
      align-items: center;
      .toutiao {
        font-size: 33px;
      }
      &::before {
        content: '';
        width: 2px;
        height: 82px;
        background-image: url(~@/assets/gradient-gray-line.png);
        position: absolute;
        left: 0;
        background-size: 100% 100%;
      }
    }
    .placeholder {
      width: 66px;
      height: 82px;
      flex-shrink: 0;
    }
  }
}
</style>>
